home *** CD-ROM | disk | FTP | other *** search
/ Motor Sport Digital Archive Collection 1960s / Motor Sport Digital Archive Collection 1960s.iso / main.swf / scripts / views / Groups / PageNavigation.as
Encoding:
Text File  |  2008-05-21  |  15.4 KB  |  486 lines

  1. package views.Groups
  2. {
  3.    import events.NavigationEvent;
  4.    import flash.events.Event;
  5.    import flash.events.KeyboardEvent;
  6.    import flash.events.MouseEvent;
  7.    import flash.ui.Keyboard;
  8.    import flash.utils.getDefinitionByName;
  9.    import model.PresentationModel;
  10.    import mx.binding.Binding;
  11.    import mx.binding.IWatcherSetupUtil;
  12.    import mx.binding.utils.ChangeWatcher;
  13.    import mx.containers.Canvas;
  14.    import mx.controls.Alert;
  15.    import mx.controls.Button;
  16.    import mx.controls.TextInput;
  17.    import mx.core.UIComponentDescriptor;
  18.    import mx.core.mx_internal;
  19.    import mx.events.FlexEvent;
  20.    import mx.events.PropertyChangeEvent;
  21.    
  22.    public class PageNavigation extends Canvas
  23.    {
  24.       private static var _watcherSetupUtil:IWatcherSetupUtil;
  25.       
  26.       private var _bindings:Array;
  27.       
  28.       public var _bindingsByDestination:Object;
  29.       
  30.       [Bindable]
  31.       private var _1456159669pageNavNextBtn:Button;
  32.       
  33.       [Bindable]
  34.       private var _709108619pageNavPrevBtn:Button;
  35.       
  36.       private var lastPageNavTxt:String;
  37.       
  38.       public var _bindingsBeginWithWord:Object;
  39.       
  40.       public var myWatcher:ChangeWatcher;
  41.       
  42.       [Bindable]
  43.       private var _1857328081presentationModel:PresentationModel;
  44.       
  45.       [Bindable]
  46.       private var _2084171470pageNavStartBtn:Button;
  47.       
  48.       [Bindable]
  49.       private var _209392814currPageText:String;
  50.       
  51.       [Bindable]
  52.       private var _706983058pageNavTxtInput:TextInput;
  53.       
  54.       private var _watchers:Array;
  55.       
  56.       [Bindable]
  57.       private var _203020107pageNavEndBtn:Button;
  58.       
  59.       private var _documentDescriptor_:UIComponentDescriptor;
  60.       
  61.       public function PageNavigation()
  62.       {
  63.          _documentDescriptor_ = new UIComponentDescriptor({
  64.             "type":Canvas,
  65.             "propertiesFactory":function():Object
  66.             {
  67.                return {
  68.                   "width":264,
  69.                   "height":36,
  70.                   "childDescriptors":[new UIComponentDescriptor({
  71.                      "type":Button,
  72.                      "id":"pageNavStartBtn",
  73.                      "events":{"click":"__pageNavStartBtn_click"},
  74.                      "propertiesFactory":function():Object
  75.                      {
  76.                         return {
  77.                            "buttonMode":true,
  78.                            "styleName":"pageNavStartBtn"
  79.                         };
  80.                      }
  81.                   }),new UIComponentDescriptor({
  82.                      "type":Button,
  83.                      "id":"pageNavPrevBtn",
  84.                      "events":{"click":"__pageNavPrevBtn_click"},
  85.                      "propertiesFactory":function():Object
  86.                      {
  87.                         return {
  88.                            "buttonMode":true,
  89.                            "styleName":"pageNavPrevBtn",
  90.                            "x":46
  91.                         };
  92.                      }
  93.                   }),new UIComponentDescriptor({
  94.                      "type":TextInput,
  95.                      "id":"pageNavTxtInput",
  96.                      "events":{"keyUp":"__pageNavTxtInput_keyUp"},
  97.                      "propertiesFactory":function():Object
  98.                      {
  99.                         return {
  100.                            "styleName":"pageNavTxtInput",
  101.                            "toolTip":"Type a number and press Enter",
  102.                            "x":92,
  103.                            "y":8,
  104.                            "width":80,
  105.                            "height":20
  106.                         };
  107.                      }
  108.                   }),new UIComponentDescriptor({
  109.                      "type":Button,
  110.                      "id":"pageNavNextBtn",
  111.                      "events":{"click":"__pageNavNextBtn_click"},
  112.                      "propertiesFactory":function():Object
  113.                      {
  114.                         return {
  115.                            "buttonMode":true,
  116.                            "styleName":"pageNavNextBtn",
  117.                            "x":172
  118.                         };
  119.                      }
  120.                   }),new UIComponentDescriptor({
  121.                      "type":Button,
  122.                      "id":"pageNavEndBtn",
  123.                      "events":{"click":"__pageNavEndBtn_click"},
  124.                      "propertiesFactory":function():Object
  125.                      {
  126.                         return {
  127.                            "buttonMode":true,
  128.                            "styleName":"pageNavEndBtn",
  129.                            "x":218
  130.                         };
  131.                      }
  132.                   })]
  133.                };
  134.             }
  135.          });
  136.          super();
  137.          mx_internal::_document = this;
  138.          this.width = 264;
  139.          this.height = 36;
  140.          this.horizontalScrollPolicy = "off";
  141.          this.verticalScrollPolicy = "off";
  142.          this.addEventListener("creationComplete",___Canvas1_creationComplete);
  143.       }
  144.       
  145.       public static function set watcherSetupUtil(param1:IWatcherSetupUtil) : void
  146.       {
  147.          PageNavigation._watcherSetupUtil = param1;
  148.       }
  149.       
  150.       private function message(param1:String) : void
  151.       {
  152.          Alert.show(param1,"Hint");
  153.       }
  154.       
  155.       private function strToPageNum(param1:String) : int
  156.       {
  157.          var _loc2_:RegExp = null;
  158.          var _loc3_:String = null;
  159.          var _loc4_:int = 0;
  160.          var _loc5_:Number = NaN;
  161.          if("1" == param1)
  162.          {
  163.             return 0;
  164.          }
  165.          _loc2_ = /[^\w&]+/gi;
  166.          _loc3_ = "";
  167.          param1 = param1.replace(_loc2_,_loc3_);
  168.          _loc4_ = int(param1.indexOf("&"));
  169.          if(-1 != _loc4_)
  170.          {
  171.             param1 = param1.substring(0,_loc4_);
  172.          }
  173.          _loc5_ = Number(param1);
  174.          if(isNaN(_loc5_))
  175.          {
  176.             return -1;
  177.          }
  178.          _loc5_ = Math.floor(_loc5_ / 2);
  179.          if(_loc5_ > presentationModel.numPages - 1)
  180.          {
  181.             return presentationModel.numPages - 1;
  182.          }
  183.          if(0 > _loc5_)
  184.          {
  185.             return 0;
  186.          }
  187.          return int(_loc5_);
  188.       }
  189.       
  190.       public function __pageNavNextBtn_click(param1:MouseEvent) : void
  191.       {
  192.          clickHandler(param1);
  193.       }
  194.       
  195.       public function pageStringListener(param1:PropertyChangeEvent) : void
  196.       {
  197.          trace("pageString has changed");
  198.          currPageText = presentationModel.pageString;
  199.       }
  200.       
  201.       public function set presentationModel(param1:PresentationModel) : void
  202.       {
  203.          var _loc2_:Object = null;
  204.          _loc2_ = this._1857328081presentationModel;
  205.          if(_loc2_ !== param1)
  206.          {
  207.             this._1857328081presentationModel = param1;
  208.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"presentationModel",_loc2_,param1));
  209.          }
  210.       }
  211.       
  212.       [Bindable(event="propertyChange")]
  213.       public function get presentationModel() : PresentationModel
  214.       {
  215.          return this._1857328081presentationModel;
  216.       }
  217.       
  218.       [Bindable(event="propertyChange")]
  219.       public function get pageNavEndBtn() : Button
  220.       {
  221.          return this._203020107pageNavEndBtn;
  222.       }
  223.       
  224.       [Bindable(event="propertyChange")]
  225.       public function get pageNavPrevBtn() : Button
  226.       {
  227.          return this._709108619pageNavPrevBtn;
  228.       }
  229.       
  230.       private function clickHandler(param1:Event) : void
  231.       {
  232.          if(-1 == presentationModel.numPages)
  233.          {
  234.             trace("-1 == numPages");
  235.             message("Use \'Browse By Cover\' to choose a magazine.");
  236.             return;
  237.          }
  238.          switch(param1.target)
  239.          {
  240.             case pageNavStartBtn:
  241.                dispatchEvent(new NavigationEvent(NavigationEvent.START_PAGE,null,true));
  242.                break;
  243.             case pageNavPrevBtn:
  244.                dispatchEvent(new NavigationEvent(NavigationEvent.PREV_PAGE,null,true));
  245.                break;
  246.             case pageNavNextBtn:
  247.                dispatchEvent(new NavigationEvent(NavigationEvent.NEXT_PAGE,null,true));
  248.                break;
  249.             case pageNavEndBtn:
  250.                dispatchEvent(new NavigationEvent(NavigationEvent.END_PAGE,null,true));
  251.                break;
  252.             case pageNavTxtInput:
  253.                handleTextInput();
  254.          }
  255.          trace("clickHandler in PageNavigation for " + param1.target);
  256.       }
  257.       
  258.       [Bindable(event="propertyChange")]
  259.       private function get currPageText() : String
  260.       {
  261.          return this._209392814currPageText;
  262.       }
  263.       
  264.       public function __pageNavStartBtn_click(param1:MouseEvent) : void
  265.       {
  266.          clickHandler(param1);
  267.       }
  268.       
  269.       private function init() : void
  270.       {
  271.          myWatcher = ChangeWatcher.watch(this,["presentationModel","pageString"],pageStringListener);
  272.       }
  273.       
  274.       public function __pageNavPrevBtn_click(param1:MouseEvent) : void
  275.       {
  276.          clickHandler(param1);
  277.       }
  278.       
  279.       public function set pageNavPrevBtn(param1:Button) : void
  280.       {
  281.          var _loc2_:Object = null;
  282.          _loc2_ = this._709108619pageNavPrevBtn;
  283.          if(_loc2_ !== param1)
  284.          {
  285.             this._709108619pageNavPrevBtn = param1;
  286.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavPrevBtn",_loc2_,param1));
  287.          }
  288.       }
  289.       
  290.       private function set currPageText(param1:String) : void
  291.       {
  292.          var _loc2_:Object = null;
  293.          _loc2_ = this._209392814currPageText;
  294.          if(_loc2_ !== param1)
  295.          {
  296.             this._209392814currPageText = param1;
  297.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"currPageText",_loc2_,param1));
  298.          }
  299.       }
  300.       
  301.       public function __pageNavTxtInput_keyUp(param1:KeyboardEvent) : void
  302.       {
  303.          keyHandler(param1);
  304.       }
  305.       
  306.       public function set pageNavEndBtn(param1:Button) : void
  307.       {
  308.          var _loc2_:Object = null;
  309.          _loc2_ = this._203020107pageNavEndBtn;
  310.          if(_loc2_ !== param1)
  311.          {
  312.             this._203020107pageNavEndBtn = param1;
  313.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavEndBtn",_loc2_,param1));
  314.          }
  315.       }
  316.       
  317.       private function handleTextInput() : void
  318.       {
  319.          var _loc1_:String = null;
  320.          var _loc2_:int = 0;
  321.          if(-1 == presentationModel.numPages)
  322.          {
  323.             trace("-1 == numPages");
  324.             message("Use \'Browse By Cover\' to choose a magazine.");
  325.             return;
  326.          }
  327.          _loc1_ = pageNavTxtInput.text;
  328.          if(_loc1_ != lastPageNavTxt)
  329.          {
  330.             _loc2_ = strToPageNum(_loc1_);
  331.             if(-1 == _loc2_)
  332.             {
  333.                message("Only numbers and \'&\' will work.  Try typing the page number, e.g. \'2\' or \'2 & 3\'");
  334.                return;
  335.             }
  336.             dispatchEvent(new NavigationEvent(NavigationEvent.SELECT_PAGE,_loc2_,true));
  337.          }
  338.       }
  339.       
  340.       public function set pageNavStartBtn(param1:Button) : void
  341.       {
  342.          var _loc2_:Object = null;
  343.          _loc2_ = this._2084171470pageNavStartBtn;
  344.          if(_loc2_ !== param1)
  345.          {
  346.             this._2084171470pageNavStartBtn = param1;
  347.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavStartBtn",_loc2_,param1));
  348.          }
  349.       }
  350.       
  351.       public function __pageNavEndBtn_click(param1:MouseEvent) : void
  352.       {
  353.          clickHandler(param1);
  354.       }
  355.       
  356.       private function formatText(param1:int) : String
  357.       {
  358.          var _loc2_:String = null;
  359.          var _loc3_:int = 0;
  360.          if(-1 == param1 || -1 == presentationModel.numPages)
  361.          {
  362.             return "";
  363.          }
  364.          _loc2_ = "" + param1.toString();
  365.          if(0 == param1)
  366.          {
  367.             _loc2_ = "" + 1;
  368.          }
  369.          else if(param1 == presentationModel.numPages - 1 && false == presentationModel.twoPageBack)
  370.          {
  371.             _loc2_ = "" + param1 * 2;
  372.          }
  373.          else
  374.          {
  375.             _loc3_ = param1 * 2;
  376.             _loc2_ = "" + _loc3_ + " & " + ++_loc3_;
  377.          }
  378.          lastPageNavTxt = _loc2_;
  379.          return _loc2_;
  380.       }
  381.       
  382.       public function ___Canvas1_creationComplete(param1:FlexEvent) : void
  383.       {
  384.          init();
  385.       }
  386.       
  387.       private function _PageNavigation_bindingExprs() : void
  388.       {
  389.          var _loc1_:* = undefined;
  390.          _loc1_ = formatText(presentationModel.currentPage);
  391.       }
  392.       
  393.       [Bindable(event="propertyChange")]
  394.       public function get pageNavStartBtn() : Button
  395.       {
  396.          return this._2084171470pageNavStartBtn;
  397.       }
  398.       
  399.       public function set pageNavTxtInput(param1:TextInput) : void
  400.       {
  401.          var _loc2_:Object = null;
  402.          _loc2_ = this._706983058pageNavTxtInput;
  403.          if(_loc2_ !== param1)
  404.          {
  405.             this._706983058pageNavTxtInput = param1;
  406.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavTxtInput",_loc2_,param1));
  407.          }
  408.       }
  409.       
  410.       private function _PageNavigation_bindingsSetup() : void
  411.       {
  412.          var binding:Binding = null;
  413.          if(!_bindings)
  414.          {
  415.             _bindings = [];
  416.          }
  417.          if(!_watchers)
  418.          {
  419.             _watchers = [];
  420.          }
  421.          binding = new Binding(this,function():String
  422.          {
  423.             var _loc1_:* = undefined;
  424.             var _loc2_:* = undefined;
  425.             _loc1_ = formatText(presentationModel.currentPage);
  426.             return _loc1_ == undefined ? null : String(_loc1_);
  427.          },function(param1:String):void
  428.          {
  429.             pageNavTxtInput.text = param1;
  430.          },"pageNavTxtInput.text");
  431.          _bindings[0] = binding;
  432.       }
  433.       
  434.       [Bindable(event="propertyChange")]
  435.       public function get pageNavTxtInput() : TextInput
  436.       {
  437.          return this._706983058pageNavTxtInput;
  438.       }
  439.       
  440.       public function set pageNavNextBtn(param1:Button) : void
  441.       {
  442.          var _loc2_:Object = null;
  443.          _loc2_ = this._1456159669pageNavNextBtn;
  444.          if(_loc2_ !== param1)
  445.          {
  446.             this._1456159669pageNavNextBtn = param1;
  447.             dispatchEvent(PropertyChangeEvent.createUpdateEvent(this,"pageNavNextBtn",_loc2_,param1));
  448.          }
  449.       }
  450.       
  451.       override public function initialize() : void
  452.       {
  453.          var target:PageNavigation = null;
  454.          var watcherSetupUtilClass:Object = null;
  455.          mx_internal::setDocumentDescriptor(_documentDescriptor_);
  456.          _PageNavigation_bindingsSetup();
  457.          target = this;
  458.          if(_watcherSetupUtil == null)
  459.          {
  460.             watcherSetupUtilClass = getDefinitionByName("_views_Groups_PageNavigationWatcherSetupUtil");
  461.             watcherSetupUtilClass["init"](null);
  462.          }
  463.          _watcherSetupUtil.setup(this,function(param1:String):*
  464.          {
  465.             return target[param1];
  466.          },_bindings,_watchers);
  467.          super.initialize();
  468.       }
  469.       
  470.       [Bindable(event="propertyChange")]
  471.       public function get pageNavNextBtn() : Button
  472.       {
  473.          return this._1456159669pageNavNextBtn;
  474.       }
  475.       
  476.       private function keyHandler(param1:KeyboardEvent) : void
  477.       {
  478.          if(param1.keyCode == Keyboard.ENTER)
  479.          {
  480.             handleTextInput();
  481.          }
  482.       }
  483.    }
  484. }
  485.  
  486.